﻿using System;
using Results.Models;

namespace Results.ViewModels
{
    public class ResultViewModel : ViewModelBase
    {
        /// <summary>
        /// Command to invoke when the selection of this item represents a selection of a player (i.e. we are showing all the players in an tournament)
        /// </summary>
        public RelayCommand PlayerSelected { get; private set; }

        /// <summary>
        /// Commmand to invoke when the selection of this item represent a selection of an tournament (i.e. we are showing all the tournaments for a particular player)
        /// </summary>
        public RelayCommand TournamentSelected { get; private set; }

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="resultModel">Source data</param>
        /// <param name="notifySelection">Methods to call if the user selects something</param>
        public ResultViewModel(ResultModel resultModel, INotifySelection notifySelection)
        {
            TournamentSelected = new RelayCommand(p => notifySelection.TournamentSelected(resultModel.TournamentModel));
            PlayerSelected = new RelayCommand(p => notifySelection.PlayerSelected(resultModel.PlayerModel));
            
            Date = resultModel.Date;
            Round1 = resultModel.Round1;
            Round2 = resultModel.Round2;
            Total = resultModel.Total;
            Points = resultModel.Points;
            Place = resultModel.Place;
            Group = resultModel.Group;
            FormattedDate = Date.ToString("MMM dd, yyyy");
            Player = resultModel.PlayerModel.LastName + ", " + resultModel.PlayerModel.FirstName;
            GraduationYear = resultModel.PlayerModel.GraduationYear;
            Tournament = resultModel.TournamentModel.Name;
        }

        String _player;
        public String Player
        {
            get
            {
                return _player;
            }
            set
            {
                if (_player != value)
                {
                    _player = value;
                    Notify("Player");
                }
            }
        }

        String _graduationYear;
        public String GraduationYear
        {
            get
            {
                return _graduationYear;
            }
            set
            {
                if (_graduationYear != value)
                {
                    _graduationYear = value;
                    Notify("GraduationYear");
                }
            }
        }

        String _tournament;
        public String Tournament
        {
            get
            {
                return _tournament;
            }
            set
            {
                if (_tournament != value)
                {
                    _tournament = value;
                    Notify("Tournament");
                }
            }
        }

        DateTime _date;
        public DateTime Date
        {
            get
            {
                return _date;
            }
            set
            {
                if (_date != value)
                {
                    _date = value;
                    Notify("Date");
                }
            }
        }

        String _formattedDate;
        public String FormattedDate
        {
            get
            {
                return _formattedDate;
            }
            set
            {
                if (_formattedDate != value)
                {
                    _formattedDate = value;
                    Notify("FormattedDate");
                }
            }
        }

        String _round1;
        public String Round1
        {
            get
            {
                return _round1;
            }
            set
            {
                if (_round1 != value)
                {
                    _round1 = value;
                    Notify("Round1");
                }
            }
        }

        String _round2;
        public String Round2
        {
            get
            {
                return _round2;
            }
            set
            {
                if (_round2 != value)
                {
                    _round2 = value;
                    Notify("Round2");
                }
            }
        }

        String _total;
        public String Total
        {
            get
            {
                return _total;
            }
            set
            {
                if (_total != value)
                {
                    _total = value;
                    Notify("Total");
                }
            }
        }

        String _points;
        public String Points
        {
            get
            {
                return _points;
            }
            set
            {
                if (_points != value)
                {
                    _points = value;
                    Notify("Points");
                }
            }
        }

        String _group;
        public String Group
        {
            get
            {
                return _group;
            }
            set
            {
                if (_group != value)
                {
                    _group = value;
                    Notify("Group");
                }
            }
        }

        String _place;
        public String Place
        {
            get
            {
                return _place;
            }
            set
            {
                if (_place != value)
                {
                    _place = value;
                    Notify("Place");
                }
            }
        }
    }
}
